<?php

/**********************************************************************
Copyright (C) FrontAccounting, LLC.
Released under the terms of the GNU General Public License, GPL, 
as published by the Free Software Foundation, either version 3 
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
$page_security = 'SA_GLANALYTIC';
// ----------------------------------------------------------------
// $ Revision:	2.0 $
// Creator:	Joe Hunt
// date_:	2005-05-19
// Title:	List of Journal Entries
// ----------------------------------------------------------------
$path_to_root = "..";

include_once ($path_to_root . "/includes/session.inc");
include_once ($path_to_root . "/includes/date_functions.inc");
include_once ($path_to_root . "/includes/data_checks.inc");
include_once ($path_to_root . "/gl/includes/gl_db.inc");
include_once ($path_to_root . "/includes/ui/ui_view.inc");
include_once ($path_to_root . "/gl/includes/db/gl_db_accounts.inc");
include_once($path_to_root . "/admin/db/fiscalyears_db.inc");

//----------------------------------------------------------------------------------------------------

print_list_of_journal_entries();

//----------------------------------------------------------------------------------------------------

function print_list_of_journal_entries()
{
    global $path_to_root, $systypes_array;

    //$from = $_POST['PARAM_0'];
    $to = $_POST['PARAM_0'];
   
    $from = get_fiscalyear_begin_for_date($to);
     
	if (date1_greater_date2($from, $to))
	   $from = $to;
       
    $from = add_days($from, -1);
    
    
    //$from = $begin;
    
    include_once ($path_to_root . "/reporting/includes/excel_report.inc");
    //	else
    //		include_once($path_to_root . "/reporting/includes/pdf_report.inc");

    $dec = user_price_dec();

    $cols = array(0,100,200,400,500,600);

    $headers = array('','','','','');

    $aligns = array('left','left','right','right','right');
        
    $comments = '';
    
    $params = array(0 => $comments, 1 => array(
            'text' => 'PADA TANGGAL',
            'from' => $from,
            'to' => $to));
    $to = add_days($to, 1);
	
    $rep = new FrontReport('NERACA', "Neraca", user_pagesize());
    $rep->formatHeaderLeft->setBottom(1);
    $rep->formatHeaderRight->setBottom(1);
    $rep->SetHeaderType('Header5');
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();

    //if ($systype == -1)
//        $systype = null;
    
    $rep->TextCol(0, 1, 'AKTIVA');    
    $rep->NewLine();
    
    $activa = 0.0;
    $total_activa = 0.0;
    
    $activa_kas = get_gl_kas();
    $kas = 0.0;
    $total_kas = 0.0;    
    while ($myrow = db_fetch($activa_kas ))
    {        
        $rep->TextCol(0, 1, get_gl_account_name($myrow['account_code']));
        $kas = get_gl_balance_from_to($from, $to, $myrow['account_code'], 0, 0);
        $total_kas += $kas;
        $rep->AmountCol(4, 5, $kas, 0);
        $rep->NewLine();
    }    
    
    $activa_invest = get_gl_investasi_pendek();    
    $invest = 0.0;
    $total_invest = 0.0;    
    while ($myrow = db_fetch($activa_invest ))
    {        
        $rep->TextCol(0, 1, get_gl_account_name($myrow['account_code']));
        $invest = get_gl_balance_from_to($from, $to, $myrow['account_code'], 0, 0);
        $total_invest += $invest;
        $rep->AmountCol(4, 5, $invest, 0);
        $rep->NewLine();
    }
        
    $activa_piutang = get_gl_piutang();    
    $piutang = 0.0;
    $total_piutang  = 0.0;    
    while ($myrow = db_fetch($activa_piutang ))
    {        
        $rep->TextCol(0, 1, get_gl_account_name($myrow['account_code']));
        $piutang = get_gl_balance_from_to($from, $to, $myrow['account_code'], 0, 0);
        $total_piutang += $piutang;
        $rep->AmountCol(4, 5, $piutang, 0);
        $rep->NewLine();
    }
        
    $activa_supplies = get_gl_supplies();    
    $supplies = 0.0;
    $total_supplies  = 0.0;    
    while ($myrow = db_fetch($activa_supplies ))
    {        
        $rep->TextCol(0, 1, get_gl_account_name($myrow['account_code']));
        $supplies = get_gl_balance_from_to($from, $to, $myrow['account_code'], 0, 0);
        $total_supplies += $supplies;
        $rep->AmountCol(4, 5, $supplies, 0);
        $rep->NewLine();
    }
        
    $activa_persediaan = get_gl_persediaan();    
    $persediaan = 0.0;
    $total_persediaan  = 0.0;    
    while ($myrow = db_fetch($activa_persediaan ))
    {        
        $rep->TextCol(0, 1, get_gl_account_name($myrow['account_code']));
        $persediaan = get_gl_balance_from_to($from, $to, $myrow['account_code'], 0, 0);
        $total_persediaan += $persediaan;
        $rep->AmountCol(4, 5, $persediaan, 0);
        $rep->NewLine();
    }
        
    $activa_uangmuka = get_gl_uang_muka();    
    $uangmuka = 0.0;
    $total_uangmuka  = 0.0;    
    while ($myrow = db_fetch($activa_uangmuka ))
    {        
        $rep->TextCol(0, 1, get_gl_account_name($myrow['account_code']));
        $uangmuka = get_gl_balance_from_to($from, $to, $myrow['account_code'], 0, 0);
        $total_uangmuka += $uangmuka;
        $rep->AmountCol(4, 5, $uangmuka, 0);
        $rep->NewLine();
    }
        
    $activa_invest_pnjg = get_gl_investasi_panjang();    
    $invest_pnjg = 0.0;
    $total_invest_pnjg  = 0.0;    
    while ($myrow = db_fetch($activa_invest_pnjg ))
    {        
        $rep->TextCol(0, 1, get_gl_account_name($myrow['account_code']));
        $invest_pnjg = get_gl_balance_from_to($from, $to, $myrow['account_code'], 0, 0);
        $total_invest_pnjg += $invest_pnjg;
        $rep->AmountCol(4, 5, $invest_pnjg, 0);
        $rep->NewLine();
    }
        
    $activa_tanah = get_gl_tanah();    
    $tanah = 0.0;
    $total_tanah  = 0.0;    
    while ($myrow = db_fetch($activa_tanah ))
    {        
        $rep->TextCol(0, 1, get_gl_account_name($myrow['account_code']));
        $tanah = get_gl_balance_from_to($from, $to, $myrow['account_code'], 0, 0);
        $total_tanah += $tanah;
        $rep->AmountCol(4, 5, $tanah, 0);
        $rep->NewLine();
    }
        
    $activa_gedung = get_gl_gedung();    
    $gedung = 0.0;
    $total_gedung  = 0.0;
    $rep->TextCol(0, 1, get_gl_account_name('13210'));    
    while ($myrow = db_fetch($activa_gedung ))    {       
        
        $gedung = get_gl_balance_from_to($from, $to, $myrow['account_code'], 0, 0);
        $total_gedung += $gedung;        
    }
    $rep->AmountCol(4, 5, $total_gedung, 0);
            $rep->NewLine();
            
    $activa_perabot_kantor = get_gl_perabot_kantor();    
    $perabot_kantor = 0.0;
    $total_perabot_kantor  = 0.0;
    $rep->TextCol(0, 1, get_gl_account_name('13310'));    
    while ($myrow = db_fetch($activa_perabot_kantor ))    {       
        
        $perabot_kantor = get_gl_balance_from_to($from, $to, $myrow['account_code'], 0, 0);
        $total_perabot_kantor += $perabot_kantor;        
    }
    $rep->AmountCol(4, 5, $total_perabot_kantor, 0);
    $rep->NewLine();
        
    $activa_kendaraan = get_gl_kendaraan();    
    $kendaraan = 0.0;
    $total_kendaraan  = 0.0;
    $rep->TextCol(0, 1, get_gl_account_name('13410'));    
    while ($myrow = db_fetch($activa_kendaraan ))    {       
        
        $kendaraan = get_gl_balance_from_to($from, $to, $myrow['account_code'], 0, 0);
        $total_kendaraan += $kendaraan;        
    }
    $rep->AmountCol(4, 5, $total_kendaraan, 0);
    $rep->NewLine();
    
    $activa_mesin_produksi = get_gl_mesin_produksi();    
    $mesin_produksi = 0.0;
    $total_mesin_produksi  = 0.0;
    $rep->TextCol(0, 1, get_gl_account_name('13510'));    
    while ($myrow = db_fetch($activa_mesin_produksi ))    {       
        
        $mesin_produksi = get_gl_balance_from_to($from, $to, $myrow['account_code'], 0, 0);
        $total_mesin_produksi += $mesin_produksi;        
    }
    $rep->AmountCol(4, 5, $total_mesin_produksi, 0);
    $rep->NewLine();     
    $rep->NewLine();     
        
    $total_activa = $total_kas + $total_invest + $total_piutang + $total_supplies + $total_persediaan + $total_uangmuka + $total_invest_pnjg +
     $total_tanah + $total_gedung + $total_perabot_kantor + $total_kendaraan + $total_mesin_produksi;
        $rep->TextCol(1, 2, 'TOTAL AKTIVA');
    $rep->AmountCol(4, 5, $total_activa, 0);
    $rep->NewLine();
    $rep->NewLine();
        
    $account_utang = get_gl_utang();
    $utang = 0.0;
    $total_utang = 0.0;
    $rep->TextCol(0, 1, 'UTANG');
    $rep->NewLine();    
    while ($myrow = db_fetch($account_utang))
    {        
        $rep->TextCol(0, 1, get_gl_account_name($myrow['account_code']));
        $utang = -(get_gl_balance_from_to($from, $to, $myrow['account_code'], 0, 0));
        $total_utang += $utang;
        $rep->AmountCol(4, 5, $utang, 0);
        $rep->NewLine();
    }
    $rep->NewLine();
        
    $rep->TextCol(1, 2, 'TOTAL UTANG');
    $rep->AmountCol(4, 5, $total_utang, 0);
    $rep->NewLine();
    $rep->NewLine();
    
    $account_modal = get_gl_modal();
    $modal = 0.0;
    $total_modal = 0.0;
    $rep->TextCol(0, 1, 'MODAL');
    $rep->NewLine();
    while ($myrow = db_fetch($account_modal))
    {        
        $rep->TextCol(0, 1, get_gl_account_name($myrow['account_code']));
        $modal = -(get_gl_balance_from_to($from, $to, $myrow['account_code'], 0, 0));
        $total_modal += $modal;
        $rep->AmountCol(4, 5, $modal, 0);
        $rep->NewLine();
    }        
    
    $account_prive = get_gl_prive();
    $prive = 0.0;
    //$total_prive = 0.0;    
    while ($myrow = db_fetch($account_prive))
    {
    	$rep->TextCol(0, 1, get_gl_account_name($myrow['account_code']));
    	$prive = get_gl_balance_from_to($from, $to, $myrow['account_code'], 0, 0);
    	$total_modal -= $prive;
    	$rep->AmountCol(4, 5, -($prive), 0);
    	$rep->NewLine();
    }
    $laba_rugi1 = get_laba_rugi($from,$to) ;
    /*$rep->TextCol(0, 1, 'laba/rugi');    
    $rep->AmountCol(4, 5, $laba_rugi1, 2);
    $rep->NewLine();*/
    $rep->TextCol(0, 1, get_gl_account_name('33000'));    
    $bal_labarugi = -(get_gl_balance_from_to($from, $to, '33000', 0, 0));
    $laba_rugi = $laba_rugi1 + $bal_labarugi;
    $total_modal += $laba_rugi;
    
    $rep->AmountCol(4, 5, $laba_rugi, 0);
    $rep->NewLine();
    
    $rep->TextCol(0, 1, get_gl_account_name('34000'));    
    $laba_ditahan = get_gl_balance_from_to($from, $to, '34000', 0, 0);    
    $total_modal += $laba_ditahan;
    
    $rep->AmountCol(4, 5, $laba_ditahan, 0);
    $rep->NewLine();
    
    $rep->TextCol(1, 2, 'TOTAL MODAL');
    $rep->AmountCol(4, 5, $total_modal, 0);
    $rep->NewLine();
    $rep->NewLine();
    $rep->NewLine();
    $rep->TextCol(1, 2, 'CONTROL BALANCE');
    $rep->AmountCol(4, 5, $total_activa - $total_utang - $total_modal, 0);
    $rep->End();
}

?>
